﻿<!-- 
    Copyright (C)  2011  chen wei hua.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 2.0
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU Free Documentation License".
 -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../common/jsp/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>选择在库品</title>
<%@ include file="../../common/jsp/config.jsp"%>
<%@ include file="../../common/jsp/pageable.jsp"%>
<script type="text/javascript" src="common/js/jquery/chinaArea/jquery.fillOptions.js"></script>
<script type="text/javascript">
	var materials;
    /**
     * Callback function that displays the content.
     *
     * Gets called every time the user clicks on a pagination link.
     *
     * @param {int} page_index New Page index
     * @param {jQuery} jq the container with the pagination links as a jQuery object
     */
    function pageselectCallback(page_index, jq){
    	var oldPageIndex = $("#pageInfo_pageIndex").val();
        if (page_index != oldPageIndex) {
        	$("#pageInfo_pageIndex").val(page_index);
        	$("#showSelectMaterialsDialog").submit();
        }
        return false;
    }

    function querySubmit() {
    	 $("#pageInfo_pageIndex").val("0");
    	 $("#showSelectMaterialsDialog").submit();
    	 return false;
    }

    function btn_close() {
    	window.returnValue = new Object();
    	self.close();
    }

    function btn_save() {
        if (!materials) {
			alert("请选择一个在库品");
			return;
        }
        var skuConfig = $(":radio[checked]");
        if (skuConfig.length == 0) {
			alert("请选择一个SKU配置");
			return;
        }
        var retObject = new Object();
        retObject.materials = materials;
        retObject.skuId = skuConfig.val();
        window.returnValue = retObject;
        self.close();
    }

    function rowSelect(row) {
        var tr = $(row);
        $("#materialsTable tr").each(function (i) {
			if (i > 0) {
				if (i % 2 == 0) {
					$(this).attr("class", "even");
				} else {
					$(this).attr("class", "odd");
				}
			}
        });
        tr.attr("class", "warning");
        var selectId = tr.find("input[type=hidden]").val();
    	var data = "materialsId=" + selectId + "&temp=" + new Date();
    	var skuConfigTable = $("#skuConfigTable");
    	$.ajax({
    	   url: "queryMaterialsJson.action",
    	   data: data,
    	   success: function(json) {
    		   materials = json;
    		   skuConfigTable.empty();
  	   	   	   var str = '<tr class="ksglxx2bg"><th width="10px" >&nbsp;</th><th width="180px" >SKU配置</th><th width="95px" >合格库存数量</th><th width="95px" >不合格数量</th><th width="95px" >待检验数量</th></tr>';
     	   	   var skuConfig = materials.skuDetails;
     	   	   for (var i in skuConfig) {
         	   	    var config = skuConfig[i];
         	   	    if (i % 2 == 0) {
         	   	    	str += '<tr class="odd">';
         	   	    } else {
             	   	    str += '<tr class="even">';
         	   	    }
         	   		str += '<td><input type="radio" name="skuConfigRadio" value="' + config.id + '"';
         	   	    if (i == 0) {
         	   	    	str += ' checked="true" ';
         	   	    }
         	   		str += '/></td>';
         	   		str += '<td>';
         	   		for (var j in config.fields) {
         	   			str += config.fields[j].customName;
         	   			str += ' ';
         	   		}
         	   		str += '</td>';
         	   		str += '<td>' + config.number + '</td>';
         	   		str += '<td>' + config.defectiveNumber + '</td>';
         	   		str += '<td>' + config.waitNumber + '</td>';
         	   		str += '</tr>';
     	   	   }
     	   	   skuConfigTable.append(str);
    	   }
    	});
    }
    
 	$(document).ready(function() {
		$("#root_category").bind("change", function() {
			var parentId = $(this).val();
			$("#mid_category").fillOptions(
					"queryMaterialsCategoryJOSN.action?categoryId=" + parentId,
					{datatype:"json",text:"name",value:"id",jsonData:"categoryList"});
		});

		$("#mid_category").bind("change", function() {
			var parentId = $(this).val();
			$("#child_category").fillOptions(
					"queryMaterialsCategoryJOSN.action?categoryId=" + parentId,
					{datatype:"json",text:"name",value:"name",jsonData:"categoryList"});
		});
	});
</script>
</head>
<base target="_self">
<body>
    <div class="subnav" align="left">
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="100%" align="left" height="31">&nbsp;<img src="common/images/title-pk.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt1">对话框</span>
			&nbsp;<img src="common/images/leftico2.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt2">选择在库品</span></td>
		  </tr>
		</table>
      </div>
<div class="main_1">
  <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D3DEEF">
    <tr align="left">
      <td bgcolor="#FFFFFF">
        <s:form action="showSelectMaterialsDialog">
      	<s:hidden id="pageInfo_pageIndex" name="pageInfo.pageIndex" />
      	<table width="670px" border="0" cellspacing="1" cellpadding="2">
        <tr>
          <td width="40px" align="right">分类</td>
          <td width="410px">
          	<s:select id="root_category"
          		name="condition.rootCategory.id"
          		list="rootCategoryList"
          		listKey="id"
          		listValue="name"
          		headerKey="-1"
          		headerValue="-请选择-" />
          	<s:select id="mid_category"
          		name="condition.category.id"
          		list="categoryList"
          		listKey="id"
          		listValue="name"
          		headerKey="-1"
          		headerValue="-请选择-" />
          	<s:select id="child_category" 
          		name="condition.name"
          		list="nameList"
          		listKey="name"
          		listValue="name"
          		headerKey=""
          		headerValue="-请选择-" />
          </td>
          <td width="80px" align="right">规格型号</td>
          <td width="160px"><s:textfield name="condition.type" size="20" /></td>
          <td width="85px" align="right">
            <input type="button" value="查询 " class="input1" onclick="querySubmit()" />
          </td>
        </tr>
        </table>
        </s:form>
      </td>
    </tr>
  </table>
</div>
	<div class="ksglxx2">
  	  <table id="materialsTable" width="100%" cellpadding="0" cellspacing="1" border="0" class="ksglxx2a">
        <tr class="ksglxx2bg">
          <th width="50px" >大分类</th>
          <th width="60px" >中分类</th>
          <th width="95px" >名称</th>
          <th width="180px" >型号</th>
		  <th width="50px">单位</th>
          <th align="left"></th>
        </tr>
        <s:iterator value="materialsList" id="materials" status="st">
          <s:if test="#st.Odd">
            <tr class="odd" onclick="rowSelect(this)">
          </s:if>
          <s:else>
            <tr class="even" onclick="rowSelect(this)">
          </s:else>
              <td><s:property value="#materials.rootCategory.name" /></td>
              <td><s:property value="#materials.category.name" /></td>
              <td><s:property value="#materials.name" /></td>
              <td><s:property value="#materials.type" /></td>
      		  <td><s:property value="#materials.units" /></td>
              <td align="center"><s:hidden value="%{#materials.id}" /></td>
            </tr>
         </s:iterator>
        </table>
		
		<!--分页开始-->
		<div style="float:right;">
			<br style="clear:both;" /> 
			<div id="Pagination"></div> 
		</div>
		<!--分页结束-->
	  </div>
	<div class="ksglxx2">
       <table id="skuConfigTable" cellpadding="0" cellspacing="1" border="0" class="ksglxx2a">
	   </table>
	</div>
     <div class="main_1">
          <table width="100%" border="0" cellpadding="5" cellspacing="1">
            <tr>
              <td align="center"><input type="button" value="确定" class="input1" onclick="btn_save()" />
              <input type="button" value="取消" class="input1" style="margin-left:20px;" onclick="btn_close()" /></td>
            </tr>
          </table>
     </div>
</body>
</base>
</html>